pub fn convert_base(num_str: &str, to_base: u32) -> String {
    // 解析输入字符串,获取数字和原始进制
    let parts: Vec<&str> = num_str.trim_end_matches(')').split('(').collect();
    if parts.len() != 2 {
        return String::from("Invalid input format");
    }
    
    let num = parts[0];
    let from_base = match parts[1].parse::<u32>() {
        Ok(base) => base,
        Err(_) => return String::from("Invalid base format")
    };
    
    // 检查进制范围是否有效
    if from_base < 2 || from_base > 16 || to_base < 2 || to_base > 16 {
        return String::from("Base must be between 2 and 16");
    }
    
    // 先将输入数字转为10进制
    let decimal = match i64::from_str_radix(num, from_base) {
        Ok(n) => n,
        Err(_) => return String::from("Invalid number format")
    };
    
    // 如果目标进制是10,直接返回
    if to_base == 10 {
        return decimal.to_string();
    }
    
    // 将10进制转换为目标进制
    let mut result = String::new();
    let mut n = decimal;
    
    while n > 0 {
        let digit = n % (to_base as i64);
        let char = match digit {
            0..=9 => (b'0' + digit as u8) as char,
            10..=15 => (b'a' + (digit - 10) as u8) as char,
            _ => unreachable!()
        };
        result.push(char);
        n /= to_base as i64;
    }
    
    // 如果结果为空(输入为0的情况),返回"0"
    if result.is_empty() {
        return "0".to_string();
    }
    
    // 反转字符串并返回结果
    result.chars().rev().collect()
}